package com.shop.tools;


import jdk.nashorn.internal.objects.NativeUint8Array;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@Configuration
@Component
public class MyExceptionHadler implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView modelAndView = new ModelAndView();
        //e.getMessage()
        //NullPointerException
        AuctionCustomerException auctionCustomerException = null;
        String aaMsg = "未知异常";
        if (e instanceof AuctionCustomerException)
        {
            auctionCustomerException = (AuctionCustomerException) e;
        }
        else
        {
            // 其他异常情况
//            auctionCustomerException = new AuctionCustomerException("未知异常..");
        }
     // 将错误信息提取出来
        aaMsg = auctionCustomerException.getMessage();
        modelAndView.addObject("errorMsg", aaMsg);
//        modelAndView.addObject("errorMsg", auctionCustomerException.getMessage());
        // 跳转到错误页面
        modelAndView.setViewName("errorPage");
        return modelAndView;
    }
}
